package com.epam.text_elements;

import java.util.Arrays;

public class Word implements SentenceComponent {
	private Symbol[] body;

	public Word(String string) {
		int stringLength=string.length();
		char[] chars=new char[stringLength];
		string.getChars(0, stringLength, chars, 0);
		body=new Symbol[chars.length];
		for (int i=0; i<chars.length; i++) {
			body[i]=new Symbol(chars[i]);
		}
	}	

	public String toString() {
		String res="";
		for (int i=0;i<body.length; i++) {
			res+=body[i].toString();
		}
		return res;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(body);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		if (!(this.toString().toLowerCase().equalsIgnoreCase(obj.toString())))
			return false;
		return true;
	}
	
}
